//Initialize Variables
var cX = 150;		//chicken X coordinate
var cY = 150;		//chicken Y coordinate
var cW = 63;		//chicken width
var cH = 75;		//chicken height
var cS = 0;			//chicken state 0=set chicken, 1=chicken out, 2=chicken bouncing, 3=chicken landed, 4=chicken died

var eX = new Array();	//explosion X
var eY = new Array();	//explosion Y
var eDX = new Array();	//explosion particle X Direction
var eDY = new Array();	//explosion particle Y Direction
var eW = new Array();	//explosion Width
var eH = new Array();	//explosion Height
var eR = new Array();	//explosion Red
var eG = new Array();	//explosion Green
var eB = new Array();	//explosion Blue
var explodeTimer = 0;

var cAnimateTimer = 0;
var cAnimateFrame = 0;

var isCollided = false;	//false if no collision. true if collided with platform
var isBouncing = false;	//true if collision with pad occurs and dY value above arbitrary limit
var bounceLock;			//int for lock from movement while "bouncing"

var gameOverCount = 0;

var dX = 0;			//chicken X direction
var dY = 1;			//chicken Y direction

var PAD_X = 255;
var PAD_Y = 385;
var PAD_WIDTH = 100;
var PAD_HEIGHT = 20;

var DIFFICULTY = 2;
var GRAVITYLINE = 190; 			//level where the gravity lessens
var LANDINGTHRESHOLD = 9;		//how slow you must be going to land instead of bounce
var TERMINALVELOCITY = 13;		//terminal velocity of AstroChicken

var score = 0;
var lives = 2;
var feed = 100;
var landed = 0;
var feedSpeed = 4;		//interval for feed decrease
var feedCount = 0;		//time to interval for feed decrease
var forceFly = 0;		//when astrochicken is forced to fly upward like a jackass
var flyVar;

var t = 0;			//transition variable; used in screen transition from title to game

var gameState = 0;	//0=title screen, 1=game

var WIDTH;			//canvas width
var HEIGHT;			//canvas height
var bc;				//background canvas
var gc;				//game canvas
var fc;				//front canvas

var gameInterval;	//main timer for the game
var imageLoadInterval;
var titleTimer;
var transitionTimer;

var imagesToLoad = 10; //total number of images and game elements that need to load prior to execution
var imagesLoaded = 0; //number of images loaded

var rightPressed = false;
var leftPressed = false;
var upPressed = false;
var downPressed = false;
var anyPressed = false;
var lastKeyPressed = null;	//used to prevent stupid javascript from repeating when key is held down (stupid!)

var soundOn = true;

var nameString = "";	//string for name for high score list

//Title Screen Vars
var titleScrollInt = 0;

var userType = document.getElementById("userTypeFld").value;
var userName = document.getElementById("userNameFld").value;

//Canvases/Layers
bc = document.getElementById("backgroundCanvas").getContext("2d");
gc = document.getElementById("gameCanvas").getContext("2d");
fc = document.getElementById("frontCanvas").getContext("2d");
WIDTH = 614;
HEIGHT = 524;

function resetVars(){
	score = 0;
	lives = 2;
	feed = 100;
	feedSpeed = 4;
	feedCount = 0;
	explodeTimer = 0;
	gameState = -1;
	t = 0;
	titleScrollInt = 0;
	
	gameOverCount = 0;
	landed = 0;
	forceFly = 0;

	DIFFICULTY = 2;
	GRAVITYLINE = 225;
	LANDINGTHRESHOLD = 10;
	TERMINALVELOCITY = 13;
}

function gameEngine(){

	switch(gameState){
		case 1:
		setNewGame();
		break;
		case 2:
		moveChicken();
		updateText();
		break;
		case 3:
		explodeChicken();
		updateText();
		break;
		case 4:
		gameOver();
		break;
		case 5:
		//enter name for high score list
		break;
		case 6:
		//do nothing because this is a really stupid design
		break;
	}

}